home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / t_sys5 / 92052tar.gz / 920528.tar / tcptimer.c < prev    next >
C/C++ Source or Header  |  1991-02-25  |  1KB  |  59 lines

  1. /* @(#) $Header: tcptimer.c,v 1.4 91/02/24 20:17:49 deyke Exp $ */
  2.  
  3. /* TCP timeout routines
  4.  * Copyright 1991 Phil Karn, KA9Q
  5.  */
  6. #include <stdio.h>
  7. #include "global.h"
  8. #include "mbuf.h"
  9. #include "timer.h"
  10. #include "netuser.h"
  11. #include "internet.h"
  12. #include "tcp.h"
  13.  
  14. /* Timer timeout */
  15. void
  16. tcp_timeout(p)
  17. void *p;
  18. {
  19.     register struct tcb *tcb;
  20.  
  21.     tcb = p;
  22.     if(tcb == NULLTCB)
  23.         return;
  24.  
  25.     /* Make sure the timer has stopped (we might have been kicked) */
  26.     stop_timer(&tcb->timer);
  27.  
  28.     switch(tcb->state){
  29.     case TCP_TIME_WAIT:     /* 2MSL timer has expired */
  30.         close_self(tcb,NORMAL);
  31.         break;
  32.     default:                /* Retransmission timer has expired */
  33.         tcb->flags.retran = 1;  /* Indicate > 1  transmission */
  34.         tcb->backoff++;
  35.         if (tcb->backoff > 10) {
  36.             close_self(tcb,TIMEOUT);
  37.             return;
  38.         }
  39.         tcb->snd.ptr = tcb->snd.una;
  40.         /* Reduce slowstart threshold to half current window */
  41.         tcb->ssthresh = tcb->cwind / 2;
  42.         tcb->ssthresh = max(tcb->ssthresh,tcb->mss);
  43.         /* Shrink congestion window to 1 packet */
  44.         tcb->cwind = tcb->mss;
  45.         tcp_output(tcb);
  46.     }
  47. }
  48. /* Backoff function - the subject of much research */
  49. int32
  50. backoff(n)
  51. int n;
  52. {
  53.     if(n > 31)
  54.         n = 31; /* Prevent truncation to zero */
  55.  
  56.     return 1L << n; /* Binary exponential back off */
  57. }
  58.  
  59.